package com.unismc.charge.collector;

import com.gitee.loyo.TokenManager;
import com.unismc.charge.collector.service.QueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

@Slf4j
@EnableScheduling
@EnableAsync
@SpringBootApplication
@ComponentScan("com.unismc")
public class ChargeCollectorApplication implements CommandLineRunner {

    @Resource
    private QueryService queryService;

    @Resource
    private TokenManager tokenManager;

    public static void main(String[] args) {
        SpringApplication.run(ChargeCollectorApplication.class, args);
    }

    /**
     * 程序启动时获取充电桩信息
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        log.info("初始化所有运营商token......");
        tokenManager.initTokens();
        log.info("初始化所有运营商token完成！");
        log.info("初始化所有充电站信息......");
        queryService.queryStationsInfo();
        log.info("初始化所有充电站信息完成！");
        log.info("初始化所有充电站状态信息......");
        queryService.queryStationsStatus();
        log.info("初始化所有充电站状态信息完成！");
        log.info("初始化所有充电站统计信息......");
        queryService.queryStationsStats();
        log.info("初始化所有充电站统计信息完成！");
    }
}
